package com.swak.algs;

import com.swak.algs.node.TreeNode;

/**
 * 二叉树的打印：先序、中序、后序
 * 
 * @author lifeng
 */
public class Code09 {

	static void printFirst(TreeNode head) {
		if (head == null) {
			return;
		}
		System.out.print(head.val + "\t");
		printFirst(head.left);
		printFirst(head.right);
	}

	static void printMiddle(TreeNode head) {
		if (head == null) {
			return;
		}
		printMiddle(head.left);
		System.out.print(head.val + "\t");
		printMiddle(head.right);
	}

	static void printLast(TreeNode head) {
		if (head == null) {
			return;
		}
		printLast(head.left);
		printLast(head.right);
		System.out.print(head.val + "\t");
	}

	public static void main(String[] args) {
		TreeNode root = TreeNode.newBlanceTree();
		printFirst(root);
		System.out.println("\n===========");
		printMiddle(root);
		System.out.println("\n===========");
		printLast(root);
	}
}
